package com.guomao.demob;

import java.util.function.Consumer;
import java.util.function.Supplier;

public class JavaDemo2 {

    public static void main(String[] args) {

      /*  method1("Hello World", new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s.concat(" javase"));
            }
        });*/

        /*method1("Hello World", (String s) -> {
            System.out.println(s.concat(" springboot"));
        });*/

        /*method1("Hello World", (String s) -> {
            System.out.println(s);
        });*/

        method1("Hello World", System.out::println);

//        method1("Hello World", s -> System.out.println(s.concat(" springboot")));


        /*method2("Hello springcloud", (s) -> {
            System.out.println(s.concat(" springcloud"));
        }, (s) -> {
            System.out.println(s.substring(5));
        });*/

        /*method2("Hello springcloud",
                s -> System.out.println(s.concat(" springcloud")),
                s -> System.out.println(s.substring(5))
        );*/

        String[] info = {"特朗普,70", "蔡徐坤,25", "东北雨姐,40"};

        method3(info, s -> {
            String[] arr = s.split(",");
            System.out.println(arr[0]);
        }, s -> {
            String[] arr = s.split(",");
            System.out.println(arr[1]);
        });
    }

    public static void method1(String str, Consumer<String> c) {
        c.accept(str);
    }

    public static void method2(String str, Consumer<String> c1, Consumer<String> c2) {
        c1.andThen(c2).accept(str);
    }

    public static void method3(String[] str, Consumer<String> c1, Consumer<String> c2) {
//        c1.andThen(c2).accept(str);
        for (String s : str) {
            c1.andThen(c2).accept(s);
        }
    }
}
